package map;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap();
        map.put("df", 45);
        map.put("er", 456);
        map.put("yh", 745);
        map.put("gf", 354);
        map.put("sd", 678);
        // 1.如何遍历Map的Key集?
        Set<String> strings = map.keySet();
        strings.forEach((s) -> System.out.println(s));
        System.out.println("------------------------------");
        // 2.遍历Map的Value
        Collection<Integer> values = map.values();
        Iterator<Integer> iterator = values.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
        System.out.println("------------------------------");
        // 3.遍历 key-value
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        Iterator<Map.Entry<String, Integer>> iterator1 = entries.iterator();
        while (iterator1.hasNext()) {
            Map.Entry<String,Integer> entry = iterator1.next();
            String key = entry.getKey();
            Integer value = entry.getValue();
            System.out.println(key + "--->" + value);
        }
    }

}
